﻿using Microsoft.EntityFrameworkCore;
using System.IO;
using TuLing.Entities;


namespace TuLing.Services
{
    public class DefaultDbContext : DbContext
    {

        public DefaultDbContext()
        {
        }

        public DefaultDbContext(DbContextOptions options) : base(options)
        {            
        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            var folder = Environment.SpecialFolder.UserProfile;
            var path = Environment.GetFolderPath(folder);
            var DbPath = Path.Join(path, "database.db3");
            
            // 如果没有配置数据库连接字符串，这里就需要配置数据库连接串
            // 否则，就没有必要配置SQLite数据库了
            optionsBuilder.UseSqlite($"Data Source={DbPath}");
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<UserRole>().HasKey(ur => new { ur.UserId, ur.RoleId });
            modelBuilder.Entity<RolePermission>().HasKey(rp => new { rp.RoleId, rp.PermissionId });

            // User(1) -> Role(*)
            modelBuilder.Entity<UserRole>()
                .HasOne(ur => ur.User)
                .WithMany(u => u.UserRoles)
                .HasForeignKey(ur => ur.UserId);

            // Role(*) -> User(1)
            modelBuilder.Entity<UserRole>()
                .HasOne(ur => ur.Role)
                .WithMany(r => r.UserRoles)
                .HasForeignKey(ur => ur.RoleId);


            // Role(1) -> Security(*)
            modelBuilder.Entity<RolePermission>()
                .HasOne(rp => rp.Role)
                .WithMany(r => r.RolePermissions)
                .HasForeignKey(rp => rp.RoleId);

            // Security(*) -> Role(1)
            modelBuilder.Entity<RolePermission>()
                .HasOne(rp => rp.Permission)
                .WithMany(p => p.RolePermissions)
                .HasForeignKey(rp => rp.PermissionId);

            CreateSeed(modelBuilder);
        }

        public DbSet<User> Users { get; set; }
        public DbSet<Role> Roles { get; set; }
        public DbSet<UserRole> UserRoles { get; set; }
        public DbSet<RolePermission> RolePermissions { get; set; }
        public DbSet<Permission> Permissions { get; set; }

        public DbSet<ProductCategory> ProductCategorys { get; set; }
        public DbSet<Product> Products { get; set; }
        public DbSet<Unit> Units { get; set; }

        public DbSet<Customer> Customers { get; set; }

        public DbSet<Supplier> Suppliers { get; set; }

        public DbSet<BuyOrder> BuyOrders { get; set; }
        public DbSet<BuyOrderDetail> BuyOrderDetails { get; set; }
        public DbSet<BuyOrderReturn> BuyOrderReturns { get; set; }
        public DbSet<BuyOrderReturnDetail> BuyOrderReturnDetails { get; set; }

        public DbSet<SaleOrder> SaleOrders { get; set; }
        public DbSet<SaleOrderDetail> SaleOrderDetails { get; set; }
        public DbSet<SaleOrderReturn> SaleOrderReturns { get; set; }
        public DbSet<SaleOrderReturnDetail> SaleOrderReturnDetails { get; set; }

        public DbSet<Finance> Finance { get; set; }
        private static void CreateSeed(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Role>().HasData(
                new Role { Id = 1, Name = "管理员", Remark = "系统管理员" },
                new Role { Id = 2, Name = "销售员", Remark = "负责销售业务" },
                new Role { Id = 3, Name = "采购员", Remark = "负责采购业务" },
                new Role { Id = 4, Name = "仓库管理员", Remark = "负责仓库管理" },
                new Role { Id = 5, Name = "财务", Remark = "负责财务管理" },
                new Role { Id = 6, Name = "客服", Remark = "负责客户服务" },
                new Role { Id = 7, Name = "运营", Remark = "负责运营管理" },
                new Role { Id = 8, Name = "市场", Remark = "负责市场推广" },
                new Role { Id = 9, Name = "技术支持", Remark = "负责技术支持" },
                new Role { Id = 10, Name = "产品经理", Remark = "负责产品管理" },
                new Role { Id = 11, Name = "测试", Remark = "负责系统测试" },
                new Role { Id = 12, Name = "人事", Remark = "负责人力资源" },
                new Role { Id = 13, Name = "审计", Remark = "负责审计工作" },
                new Role { Id = 14, Name = "外部顾问", Remark = "外部专家顾问" },
                new Role { Id = 15, Name = "访客", Remark = "只读权限" }
            );

            modelBuilder.Entity<User>().HasData(
                new User { Id = 1, Account = "admin", Name = "宋江", Password = "123456", Remark = "及时雨，水浒传首领，仗义疏财，号召力强。", Phone = "13800000001" },
                new User { Id = 2, Account = "user01", Name = "卢俊义", Password = "123456", Remark = "玉麒麟，武艺高强，梁山第二把交椅。", Phone = "13800000002" },
                new User { Id = 3, Account = "user02", Name = "吴用", Password = "123456", Remark = "智多星，足智多谋，梁山军师。", Phone = "13800000003" },
                new User { Id = 4, Account = "user03", Name = "公孙胜", Password = "123456", Remark = "入云龙，道术高强，善使法术。", Phone = "13800000004" },
                new User { Id = 5, Account = "user04", Name = "关胜", Password = "123456", Remark = "大刀，关羽后人，勇猛善战。", Phone = "13800000005" },
                new User { Id = 6, Account = "user05", Name = "林冲", Password = "123456", Remark = "豹子头，八十万禁军教头，枪法高强。", Phone = "13800000006" },
                new User { Id = 7, Account = "user06", Name = "秦明", Password = "123456", Remark = "霹雳火，勇猛刚烈，善使狼牙棒。", Phone = "13800000007" },
                new User { Id = 8, Account = "user07", Name = "呼延灼", Password = "123456", Remark = "双鞭将，善使双鞭，原朝廷大将。", Phone = "13800000008" },
                new User { Id = 9, Account = "user08", Name = "花荣", Password = "123456", Remark = "小李广，箭法如神，宋江挚友。", Phone = "13800000009" },
                new User { Id = 10, Account = "user09", Name = "柴进", Password = "123456", Remark = "小旋风，豪门世家，仗义疏财。", Phone = "13800000010" },
                new User { Id = 11, Account = "user10", Name = "李应", Password = "123456", Remark = "扑天雕，武艺高强，性格刚直。", Phone = "13800000011" },
                new User { Id = 12, Account = "user11", Name = "朱仝", Password = "123456", Remark = "美髯公，忠厚仁义，善使长枪。", Phone = "13800000012" },
                new User { Id = 13, Account = "user12", Name = "鲁智深", Password = "123456", Remark = "花和尚，力大无穷，性格豪爽。", Phone = "13800000013" },
                new User { Id = 14, Account = "user13", Name = "武松", Password = "123456", Remark = "行者，打虎英雄，刚烈正直。", Phone = "13800000014" },
                new User { Id = 15, Account = "user14", Name = "董平", Password = "123456", Remark = "双枪将，武艺高强，勇猛善战。", Phone = "13800000015" },
                new User { Id = 16, Account = "qinshi_huang", Name = "秦始皇", Password = "123456", Remark = "中国第一个皇帝，统一六国，创立秦朝。", Phone = "13900000016" },
                new User { Id = 17, Account = "liubang", Name = "刘邦", Password = "123456", Remark = "汉高祖，汉朝开国皇帝，推翻秦朝。", Phone = "13900000017" },
                new User { Id = 18, Account = "liusheng", Name = "刘彻", Password = "123456", Remark = "汉武帝，开疆拓土，推行推恩令。", Phone = "13900000018" },
                new User { Id = 19, Account = "caocao", Name = "曹操", Password = "123456", Remark = "三国时期魏国奠基人，政治家、军事家、诗人。", Phone = "13900000019" },
                new User { Id = 20, Account = "liubei", Name = "刘备", Password = "123456", Remark = "三国时期蜀汉开国皇帝，仁德之主。", Phone = "13900000020" },
                new User { Id = 21, Account = "sunquan", Name = "孙权", Password = "123456", Remark = "三国时期吴国开国皇帝，善于用人。", Phone = "15000000021" },
                new User { Id = 22, Account = "zhugeliang", Name = "诸葛亮", Password = "123456", Remark = "三国时期蜀汉丞相，睿智多谋，鞠躬尽瘁。", Phone = "15000000022" },
                new User { Id = 23, Account = "simayi", Name = "司马懿", Password = "123456", Remark = "三国时期魏国重臣，后晋朝奠基人。", Phone = "15000000023" },
                new User { Id = 24, Account = "sunwu", Name = "孙武", Password = "123456", Remark = "春秋时期著名军事家，《孙子兵法》作者。", Phone = "15000000024" },
                new User { Id = 25, Account = "wuzetian", Name = "武则天", Password = "123456", Remark = "中国历史上唯一的女皇帝，唐朝女皇。", Phone = "15000000025" },
                new User { Id = 26, Account = "liubang", Name = "刘邦", Password = "123456", Remark = "汉高祖，汉朝开国皇帝。", Phone = "15100000026" },
                new User { Id = 27, Account = "liubian", Name = "刘备", Password = "123456", Remark = "三国蜀汉开国皇帝。", Phone = "15100000027" },
                new User { Id = 28, Account = "liusheng", Name = "刘秀", Password = "123456", Remark = "东汉开国皇帝，光武中兴。", Phone = "15100000028" },
                new User { Id = 29, Account = "liyu", Name = "李煜", Password = "123456", Remark = "南唐后主，著名词人。", Phone = "15100000029" },
                new User { Id = 30, Account = "yuefei", Name = "岳飞", Password = "123456", Remark = "南宋抗金名将，精忠报国。", Phone = "15100000030" },
                new User { Id = 31, Account = "wen_tianxiang", Name = "文天祥", Password = "123456", Remark = "南宋末年民族英雄，正气歌作者。", Phone = "15200000031" },
                new User { Id = 32, Account = "zhugeliang", Name = "诸葛亮", Password = "123456", Remark = "三国蜀汉丞相，睿智多谋。", Phone = "15200000032" },
                new User { Id = 33, Account = "li_shimin", Name = "李世民", Password = "123456", Remark = "唐太宗，贞观之治缔造者。", Phone = "15200000033" },
                new User { Id = 34, Account = "yangguifei", Name = "杨贵妃", Password = "123456", Remark = "唐玄宗宠妃，四大美女之一。", Phone = "15200000034" },
                new User { Id = 35, Account = "bai_juyi", Name = "白居易", Password = "123456", Remark = "唐代大诗人，代表作《长恨歌》。", Phone = "15200000035" },
                new User { Id = 36, Account = "dufu", Name = "杜甫", Password = "123456", Remark = "唐代伟大现实主义诗人，被称为诗圣", Phone = "15500000036" },
                new User { Id = 37, Account = "libai", Name = "李白", Password = "123456", Remark = "唐代浪漫主义诗人，被称为诗仙", Phone = "15500000037" },
                new User { Id = 38, Account = "wangwei", Name = "王维", Password = "123456", Remark = "唐代诗人、画家，诗佛。", Phone = "15500000038" },
                new User { Id = 39, Account = "su_dongpo", Name = "苏轼", Password = "123456", Remark = "北宋文学家、书画家，号东坡居士。", Phone = "15500000039" },
                new User { Id = 40, Account = "ouyangxiu", Name = "欧阳修", Password = "123456", Remark = "北宋文学家，唐宋八大家之一。", Phone = "15500000040" },
                new User { Id = 41, Account = "simaqian", Name = "司马迁", Password = "123456", Remark = "西汉史学家，《史记》作者。", Phone = "15600000041" },
                new User { Id = 42, Account = "zhugejin", Name = "诸葛瑾", Password = "123456", Remark = "三国东吴重臣，诸葛亮之兄。", Phone = "15600000042" },
                new User { Id = 43, Account = "zhangfei", Name = "张飞", Password = "123456", Remark = "三国蜀汉名将，勇猛善战。", Phone = "15600000043" },
                new User { Id = 44, Account = "guanyu", Name = "关羽", Password = "123456", Remark = "三国蜀汉名将，义薄云天。", Phone = "15600000044" },
                new User { Id = 45, Account = "zhaoyun", Name = "赵云", Password = "123456", Remark = "三国蜀汉名将，常胜将军。", Phone = "15600000045" },
                new User { Id = 46, Account = "machao", Name = "马超", Password = "123456", Remark = "三国蜀汉名将，西凉锦马超。", Phone = "15700000046" },
                new User { Id = 47, Account = "huangzhong", Name = "黄忠", Password = "123456", Remark = "三国蜀汉老将，百步穿杨。", Phone = "15700000047" },
                new User { Id = 48, Account = "sunce", Name = "孙策", Password = "123456", Remark = "三国东吴奠基人，小霸王。", Phone = "15700000048" },
                new User { Id = 49, Account = "zhouyu", Name = "周瑜", Password = "123456", Remark = "三国东吴大都督，英俊潇洒。", Phone = "15700000049" },
                new User { Id = 50, Account = "lu_sun", Name = "陆逊", Password = "123456", Remark = "三国东吴名将，火烧夷陵。", Phone = "15700000050" },
                new User { Id = 51, Account = "lvbu", Name = "吕布", Password = "123456", Remark = "三国著名武将，勇冠三军。", Phone = "15800000051" },
                new User { Id = 52, Account = "diaochan", Name = "貂蝉", Password = "123456", Remark = "三国时期美女，王允义女，四大美女之一。", Phone = "15800000052" },
                new User { Id = 53, Account = "xunyu", Name = "荀彧", Password = "123456", Remark = "三国曹魏谋士，王佐之才。", Phone = "15800000053" },
                new User { Id = 54, Account = "guojia", Name = "郭嘉", Password = "123456", Remark = "三国曹魏谋士，英年早逝。", Phone = "15800000054" },
                new User { Id = 55, Account = "zhenji", Name = "甄氏", Password = "123456", Remark = "三国魏文帝曹丕皇后，才貌双全。", Phone = "15800000055" },
                new User { Id = 56, Account = "liubei", Name = "刘备", Password = "123456", Remark = "三国蜀汉开国皇帝，仁德之主。", Phone = "15900000056" },
                new User { Id = 57, Account = "zhangliao", Name = "张辽", Password = "123456", Remark = "三国曹魏名将，威震逍遥津。", Phone = "15900000057" },
                new User { Id = 58, Account = "sunshangxiang", Name = "孙尚香", Password = "123456", Remark = "三国东吴公主，刘备之妻。", Phone = "15900000058" },
                new User { Id = 59, Account = "liubei", Name = "刘禅", Password = "123456", Remark = "三国蜀汉后主，刘备之子。", Phone = "15900000059" },
                new User { Id = 60, Account = "zhugedan", Name = "诸葛诞", Password = "123456", Remark = "三国曹魏名将，诸葛瑾之子。", Phone = "15900000060" },
                new User { Id = 61, Account = "liqingzhao", Name = "李清照", Password = "123456", Remark = "宋代女词人，易安居士，婉约派代表。", Phone = "16600000061" },
                new User { Id = 62, Account = "xin_qiji", Name = "辛弃疾", Password = "123456", Remark = "南宋豪放派词人，爱国志士。", Phone = "16600000062" },
                new User { Id = 63, Account = "yuefei", Name = "岳飞", Password = "123456", Remark = "南宋抗金名将，精忠报国。", Phone = "16600000063" },
                new User { Id = 64, Account = "hanxin", Name = "韩信", Password = "123456", Remark = "西汉开国名将，兵仙。", Phone = "16600000064" },
                new User { Id = 65, Account = "zhangqian", Name = "张骞", Password = "123456", Remark = "西汉外交家，开辟丝绸之路。", Phone = "16600000065" },
                new User { Id = 66, Account = "ban_chao", Name = "班超", Password = "123456", Remark = "东汉名将，经营西域。", Phone = "17300000066" },
                new User { Id = 67, Account = "zhangheng", Name = "张衡", Password = "123456", Remark = "东汉科学家，发明地动仪。", Phone = "17300000067" },
                new User { Id = 68, Account = "hua_tuo", Name = "华佗", Password = "123456", Remark = "东汉医学家，外科圣手。", Phone = "17300000068" },
                new User { Id = 69, Account = "simaguang", Name = "司马光", Password = "123456", Remark = "北宋史学家，《资治通鉴》作者。", Phone = "17300000069" },
                new User { Id = 70, Account = "zhuxi", Name = "朱熹", Password = "123456", Remark = "南宋理学家，理学集大成者。", Phone = "17300000070" },
                new User { Id = 71, Account = "wangyangming", Name = "王阳明", Password = "123456", Remark = "明代思想家，心学创立者。", Phone = "17500000071" },
                new User { Id = 72, Account = "zhenghe", Name = "郑和", Password = "123456", Remark = "明代航海家，七下西洋。", Phone = "17500000072" },
                new User { Id = 73, Account = "li_shizhen", Name = "李时珍", Password = "123456", Remark = "明代医学家，《本草纲目》作者。", Phone = "17500000073" },
                new User { Id = 74, Account = "xu_xiake", Name = "徐霞客", Password = "123456", Remark = "明代地理学家，旅行家。", Phone = "17500000074" },
                new User { Id = 75, Account = "linzexu", Name = "林则徐", Password = "123456", Remark = "清代民族英雄，虎门销烟。", Phone = "17500000075" },
                new User { Id = 76, Account = "zengguofan", Name = "曾国藩", Password = "123456", Remark = "清末重臣，湘军创立者。", Phone = "17800000076" },
                new User { Id = 77, Account = "lihongzhang", Name = "李鸿章", Password = "123456", Remark = "清末洋务派代表，北洋大臣。", Phone = "17800000077" },
                new User { Id = 78, Account = "zhangzizhong", Name = "张自忠", Password = "123456", Remark = "抗日名将，壮烈殉国。", Phone = "17800000078" },
                new User { Id = 79, Account = "dengxiaoping", Name = "邓小平", Password = "123456", Remark = "中国改革开放总设计师。", Phone = "17800000079" },
                new User { Id = 80, Account = "zhouenlai", Name = "周恩来", Password = "123456", Remark = "新中国开国总理，杰出外交家。", Phone = "17800000080" },
                new User { Id = 81, Account = "sunzhongshan", Name = "孙中山", Password = "123456", Remark = "中国民主革命先行者，国父。", Phone = "18800000081" },
                new User { Id = 82, Account = "liangqichao", Name = "梁启超", Password = "123456", Remark = "近代思想家，戊戌变法领袖。", Phone = "18800000082" },
                new User { Id = 83, Account = "qiu_jin", Name = "秋瑾", Password = "123456", Remark = "近代女革命家，巾帼英雄。", Phone = "18800000083" },
                new User { Id = 84, Account = "lu_xun", Name = "鲁迅", Password = "123456", Remark = "现代文学家，思想启蒙者。", Phone = "18800000084" },
                new User { Id = 85, Account = "ba_jin", Name = "巴金", Password = "123456", Remark = "现代作家，《家》《春》《秋》作者。", Phone = "18800000085" },
                new User { Id = 86, Account = "lao_she", Name = "老舍", Password = "123456", Remark = "现代作家，《骆驼祥子》作者。", Phone = "19800000086" },
                new User { Id = 87, Account = "maozedong", Name = "毛泽东", Password = "123456", Remark = "中国共产党主要缔造者，伟大领袖。", Phone = "19800000087" },
                new User { Id = 88, Account = "jiangjieshi", Name = "蒋介石", Password = "123456", Remark = "国民党领袖，近代历史人物。", Phone = "19800000088" },
                new User { Id = 89, Account = "liangshuming", Name = "梁漱溟", Password = "123456", Remark = "现代哲学家，乡村建设运动倡导者。", Phone = "19800000089" },
                new User { Id = 90, Account = "hu_shi", Name = "胡适", Password = "123456", Remark = "现代学者，新文化运动代表。", Phone = "19800000090" },
                new User { Id = 91, Account = "chen_duxiu", Name = "陈独秀", Password = "123456", Remark = "新文化运动领袖，中共创始人之一。", Phone = "19900000091" },
                new User { Id = 92, Account = "li_dazhao", Name = "李大钊", Password = "123456", Remark = "中国共产党创始人之一，革命先驱。", Phone = "19900000092" },
                new User { Id = 93, Account = "zhangxueliang", Name = "张学良", Password = "123456", Remark = "东北少帅，西安事变主角。", Phone = "19900000093" },
                new User { Id = 94, Account = "songqingling", Name = "宋庆龄", Password = "123456", Remark = "国母，孙中山夫人，国家领导人。", Phone = "19900000094" },
                new User { Id = 95, Account = "songmeiling", Name = "宋美龄", Password = "123456", Remark = "蒋介石夫人，著名外交家。", Phone = "19900000095" },
                new User { Id = 96, Account = "liangsid", Name = "梁思成", Password = "123456", Remark = "著名建筑学家，古建筑保护专家。", Phone = "19900000096" },
                new User { Id = 97, Account = "qianxuesen", Name = "钱学森", Password = "123456", Remark = "中国航天之父，科学家。", Phone = "19900000097" },
                new User { Id = 98, Account = "dengyingchao", Name = "邓颖超", Password = "123456", Remark = "妇女运动领袖，周恩来夫人。", Phone = "19900000098" },
                new User { Id = 99, Account = "liangqichao", Name = "梁启超", Password = "123456", Remark = "近代思想家，戊戌变法领袖。", Phone = "19900000099" },
                new User { Id = 100, Account = "zhangtaiyan", Name = "章太炎", Password = "123456", Remark = "近代思想家，国学大师。", Phone = "19900000100" },
                new User { Id = 101, Account = "admin", Name = "章太炎", Password = "123456", Remark = "近代思想家，国学大师。", Phone = "19900000101" }
            );
            modelBuilder.Entity<Permission>().HasData(
                new Permission { Id = 1, UniqueCode = "User_View", UniqueName = "用户查看" },
                new Permission { Id = 2, UniqueCode = "User_Edit", UniqueName = "用户编辑" },
                new Permission { Id = 3, UniqueCode = "User_Delete", UniqueName = "用户删除" },
                new Permission { Id = 4, UniqueCode = "Role_View", UniqueName = "角色查看" },
                new Permission { Id = 5, UniqueCode = "Role_Edit", UniqueName = "角色编辑" },
                new Permission { Id = 6, UniqueCode = "Role_Delete", UniqueName = "角色删除" },
                new Permission { Id = 7, UniqueCode = "Permission_View", UniqueName = "权限查看" },
                new Permission { Id = 8, UniqueCode = "Permission_Edit", UniqueName = "权限编辑" },
                new Permission { Id = 9, UniqueCode = "Permission_Delete", UniqueName = "权限删除" },
                new Permission { Id = 10, UniqueCode = "Product_View", UniqueName = "产品查看" },
                new Permission { Id = 11, UniqueCode = "Product_Edit", UniqueName = "产品编辑" },
                new Permission { Id = 12, UniqueCode = "Product_Delete", UniqueName = "产品删除" },
                new Permission { Id = 13, UniqueCode = "Order_View", UniqueName = "订单查看" },
                new Permission { Id = 14, UniqueCode = "Order_Edit", UniqueName = "订单编辑" },
                new Permission { Id = 15, UniqueCode = "Order_Delete", UniqueName = "订单删除" }
            );
            
            modelBuilder.Entity<UserRole>().HasData(
                new UserRole { UserId = 1, RoleId = 1 },
                new UserRole { UserId = 2, RoleId = 2 },
                new UserRole { UserId = 3, RoleId = 3 },
                new UserRole { UserId = 4, RoleId = 4 },
                new UserRole { UserId = 5, RoleId = 5 },
                new UserRole { UserId = 6, RoleId = 6 },
                new UserRole { UserId = 7, RoleId = 7 },
                new UserRole { UserId = 8, RoleId = 8 },
                new UserRole { UserId = 9, RoleId = 9 },
                new UserRole { UserId = 10, RoleId = 10 },
                new UserRole { UserId = 11, RoleId = 11 },
                new UserRole { UserId = 12, RoleId = 12 },
                new UserRole { UserId = 13, RoleId = 13 },
                new UserRole { UserId = 14, RoleId = 14 },
                new UserRole { UserId = 15, RoleId = 15 }
            );

            modelBuilder.Entity<RolePermission>().HasData(
                new RolePermission { RoleId = 1, PermissionId = 1 },
                new RolePermission { RoleId = 2, PermissionId = 2 },
                new RolePermission { RoleId = 3, PermissionId = 3 },
                new RolePermission { RoleId = 4, PermissionId = 4 },
                new RolePermission { RoleId = 5, PermissionId = 5 },
                new RolePermission { RoleId = 6, PermissionId = 6 },
                new RolePermission { RoleId = 7, PermissionId = 7 },
                new RolePermission { RoleId = 8, PermissionId = 8 },
                new RolePermission { RoleId = 9, PermissionId = 9 },
                new RolePermission { RoleId = 10, PermissionId = 10 },
                new RolePermission { RoleId = 11, PermissionId = 11 },
                new RolePermission { RoleId = 12, PermissionId = 12 },
                new RolePermission { RoleId = 13, PermissionId = 13 },
                new RolePermission { RoleId = 14, PermissionId = 14 },
                new RolePermission { RoleId = 15, PermissionId = 15 }
            );

            modelBuilder.Entity<Unit>().HasData(
                new Unit() { Id = 1, Name = "个" },
                new Unit() { Id = 2, Name = "斤" },
                new Unit() { Id = 3, Name = "米" },
                new Unit() { Id = 4, Name = "卷" },
                new Unit() { Id = 5, Name = "箱" },
                new Unit() { Id = 6, Name = "包" },
                new Unit() { Id = 7, Name = "台" }
            );

            modelBuilder.Entity<ProductCategory>().HasData(
                    new ProductCategory() { Id = 1, Code = "001", Name = "全部", ParentId = 0, },
                    new ProductCategory() { Id = 2, Code = "002", Name = "电脑", ParentId = 1, },
                    new ProductCategory() { Id = 3, Code = "003", Name = "手机", ParentId = 1  }
            );

            modelBuilder.Entity<Product>().HasData(
                    new Product
                    {
                        Id = 1,
                        ProductCategoryId = 2, // 电脑
                        Code = "PC001",
                        Name = "联想笔记本",
                        Unit = "台",
                        Price = 4500.00m,
                        Remark = "高性能办公本"
                    },
                    new Product
                    {
                        Id = 2,
                        ProductCategoryId = 2, // 电脑
                        Code = "PC002",
                        Name = "戴尔台式机",
                        Unit = "台",
                        Price = 3800.00m,
                        Remark = "家用台式机"
                    },
                    new Product
                    {
                        Id = 3,
                        ProductCategoryId = 3, // 手机
                        Code = "PH001",
                        Name = "三星手机",
                        Unit = "个",
                        Price = 3200.00m,
                        Remark = "畅销款"
                    },
                    new Product
                    {
                        Id = 4,
                        ProductCategoryId = 3, // 手机
                        Code = "PH002",
                        Name = "苹果手机",
                        Unit = "个",
                        Price = 6800.00m,
                        Remark = "旗舰款"
                    }
                );

            modelBuilder.Entity<Customer>().HasData(
                 new Customer { Id = 1, Name = "张三", Phone = "13800000001", Address = "北京市朝阳区", Remark = "VIP客户" },
                 new Customer { Id = 2, Name = "李四", Phone = "13800000002", Address = "上海市浦东新区", Remark = "普通客户" },
                 new Customer { Id = 3, Name = "王五", Phone = "13800000003", Address = "广州市天河区", Remark = "新客户" },
                 new Customer { Id = 4, Name = "赵六", Phone = "13800000004", Address = "深圳市南山区", Remark = "" },
                 new Customer { Id = 5, Name = "钱七", Phone = "13800000005", Address = "杭州市西湖区", Remark = "" },
                 new Customer { Id = 6, Name = "孙八", Phone = "13800000006", Address = "成都市武侯区", Remark = "" },
                 new Customer { Id = 7, Name = "周九", Phone = "13800000007", Address = "重庆市渝中区", Remark = "" },
                 new Customer { Id = 8, Name = "吴十", Phone = "13800000008", Address = "南京市鼓楼区", Remark = "" },
                 new Customer { Id = 9, Name = "郑十一", Phone = "13800000009", Address = "苏州市工业园区", Remark = "" },
                 new Customer { Id = 10, Name = "王十二", Phone = "13800000010", Address = "武汉市江汉区", Remark = "" },
                 new Customer { Id = 11, Name = "冯十三", Phone = "13800000011", Address = "天津市和平区", Remark = "" },
                 new Customer { Id = 12, Name = "陈十四", Phone = "13800000012", Address = "青岛市市南区", Remark = "" },
                 new Customer { Id = 13, Name = "褚十五", Phone = "13800000013", Address = "沈阳市和平区", Remark = "" },
                 new Customer { Id = 14, Name = "卫十六", Phone = "13800000014", Address = "大连市中山区", Remark = "" },
                 new Customer { Id = 15, Name = "蒋十七", Phone = "13800000015", Address = "厦门市思明区", Remark = "" },
                 new Customer { Id = 16, Name = "沈十八", Phone = "13800000016", Address = "福州市鼓楼区", Remark = "" },
                 new Customer { Id = 17, Name = "韩十九", Phone = "13800000017", Address = "济南市历下区", Remark = "" },
                 new Customer { Id = 18, Name = "杨二十", Phone = "13800000018", Address = "合肥市庐阳区", Remark = "" },
                 new Customer { Id = 19, Name = "朱二一", Phone = "13800000019", Address = "郑州市金水区", Remark = "" },
                 new Customer { Id = 20, Name = "秦二二", Phone = "13800000020", Address = "长沙市芙蓉区", Remark = "" }
             );

            modelBuilder.Entity<Supplier>().HasData(
                new Supplier { Id = 1, Name = "供应商一", Phone = "13900000001", Address = "上海市黄浦区", Remark = "主营电子元件" },
                new Supplier { Id = 2, Name = "供应商二", Phone = "13900000002", Address = "北京市海淀区", Remark = "主营办公用品" },
                new Supplier { Id = 3, Name = "供应商三", Phone = "13900000003", Address = "深圳市南山区", Remark = "主营电脑配件" },
                new Supplier { Id = 4, Name = "供应商四", Phone = "13900000004", Address = "广州市天河区", Remark = "主营手机配件" },
                new Supplier { Id = 5, Name = "供应商五", Phone = "13900000005", Address = "杭州市西湖区", Remark = "主营办公家具" },
                new Supplier { Id = 6, Name = "供应商六", Phone = "13900000006", Address = "成都市武侯区", Remark = "主营网络设备" },
                new Supplier { Id = 7, Name = "供应商七", Phone = "13900000007", Address = "重庆市渝中区", Remark = "主营安防产品" },
                new Supplier { Id = 8, Name = "供应商八", Phone = "13900000008", Address = "南京市鼓楼区", Remark = "主营打印耗材" },
                new Supplier { Id = 9, Name = "供应商九", Phone = "13900000009", Address = "苏州市工业园区", Remark = "主营包装材料" },
                new Supplier { Id = 10, Name = "供应商十", Phone = "13900000010", Address = "武汉市江汉区", Remark = "主营办公设备" },
                new Supplier { Id = 11, Name = "供应商十一", Phone = "13900000011", Address = "天津市和平区", Remark = "主营照明设备" },
                new Supplier { Id = 12, Name = "供应商十二", Phone = "13900000012", Address = "青岛市市南区", Remark = "主营五金工具" },
                new Supplier { Id = 13, Name = "供应商十三", Phone = "13900000013", Address = "沈阳市和平区", Remark = "主营化工原料" },
                new Supplier { Id = 14, Name = "供应商十四", Phone = "13900000014", Address = "大连市中山区", Remark = "主营仪器仪表" },
                new Supplier { Id = 15, Name = "供应商十五", Phone = "13900000015", Address = "厦门市思明区", Remark = "主营食品原料" },
                new Supplier { Id = 16, Name = "供应商十六", Phone = "13900000016", Address = "福州市鼓楼区", Remark = "主营日用百货" },
                new Supplier { Id = 17, Name = "供应商十七", Phone = "13900000017", Address = "济南市历下区", Remark = "主营建材" },
                new Supplier { Id = 18, Name = "供应商十八", Phone = "13900000018", Address = "合肥市庐阳区", Remark = "主营家用电器" },
                new Supplier { Id = 19, Name = "供应商十九", Phone = "13900000019", Address = "郑州市金水区", Remark = "主营文体用品" },
                new Supplier { Id = 20, Name = "供应商二十", Phone = "13900000020", Address = "长沙市芙蓉区", Remark = "主营清洁用品" }
            );
            modelBuilder.Entity<Finance>().HasData(
                new Finance { Id = 1, Code = "F20230101", CreatedAt = new DateTime(2023, 1, 1), FormType = 1, Amount = 1200.00m, Item = "销售收入", Remark = "销售商品收入" },
                new Finance { Id = 2, Code = "F20230102", CreatedAt = new DateTime(2023, 1, 2), FormType = 2, Amount = -800.00m, Item = "采购支出", Remark = "采购原材料" },
                new Finance { Id = 3, Code = "F20230103", CreatedAt = new DateTime(2023, 1, 3), FormType = 1, Amount = -300.00m, Item = "办公支出", Remark = "购买办公用品" },
                new Finance { Id = 4, Code = "F20230104", CreatedAt = new DateTime(2023, 1, 4), FormType = 2, Amount = 1500.00m, Item = "销售收入", Remark = "销售商品收入" },
                new Finance { Id = 5, Code = "F20230105", CreatedAt = new DateTime(2023, 1, 5), FormType = 1, Amount = -400.00m, Item = "运输支出", Remark = "物流运输费" },
                new Finance { Id = 6, Code = "F20230106", CreatedAt = new DateTime(2023, 1, 6), FormType = 2, Amount = -2000.00m, Item = "工资支出", Remark = "发放员工工资" },
                new Finance { Id = 7, Code = "F20230107", CreatedAt = new DateTime(2023, 1, 7), FormType = 1, Amount = 1800.00m, Item = "销售收入", Remark = "销售商品收入" },
                new Finance { Id = 8, Code = "F20230108", CreatedAt = new DateTime(2023, 1, 8), FormType = 2, Amount = -900.00m, Item = "采购支出", Remark = "采购原材料" },
                new Finance { Id = 9, Code = "F20230109", CreatedAt = new DateTime(2023, 1, 9), FormType = 1, Amount = 600.00m, Item = "利息收入", Remark = "银行存款利息" },
                new Finance { Id = 10, Code = "F20230110", CreatedAt = new DateTime(2023, 1, 10), FormType = 2, Amount = -150.00m, Item = "办公支出", Remark = "购买办公用品" },
                new Finance { Id = 11, Code = "F20230201", CreatedAt = new DateTime(2023, 2, 1), FormType = 1, Amount = 2000.00m, Item = "销售收入", Remark = "销售商品收入" },
                new Finance { Id = 12, Code = "F20230202", CreatedAt = new DateTime(2023, 2, 2), FormType = 2, Amount = -1200.00m, Item = "采购支出", Remark = "采购原材料" },
                new Finance { Id = 13, Code = "F20230203", CreatedAt = new DateTime(2023, 2, 3), FormType = 1, Amount = -350.00m, Item = "办公支出", Remark = "购买办公用品" },
                new Finance { Id = 14, Code = "F20230204", CreatedAt = new DateTime(2023, 2, 4), FormType = 2, Amount = 1700.00m, Item = "销售收入", Remark = "销售商品收入" },
                new Finance { Id = 15, Code = "F20230205", CreatedAt = new DateTime(2023, 2, 5), FormType = 1, Amount = -500.00m, Item = "运输支出", Remark = "物流运输费" },
                new Finance { Id = 16, Code = "F20230206", CreatedAt = new DateTime(2023, 2, 6), FormType = 2, Amount = -2100.00m, Item = "工资支出", Remark = "发放员工工资" },
                new Finance { Id = 17, Code = "F20230207", CreatedAt = new DateTime(2023, 2, 7), FormType = 1, Amount = 1600.00m, Item = "销售收入", Remark = "销售商品收入" },
                new Finance { Id = 18, Code = "F20230208", CreatedAt = new DateTime(2023, 2, 8), FormType = 2, Amount = -950.00m, Item = "采购支出", Remark = "采购原材料" },
                new Finance { Id = 19, Code = "F20230209", CreatedAt = new DateTime(2023, 2, 9), FormType = 1, Amount = 700.00m, Item = "利息收入", Remark = "银行存款利息" },
                new Finance { Id = 20, Code = "F20230210", CreatedAt = new DateTime(2023, 2, 10), FormType = 2, Amount = -180.00m, Item = "办公支出", Remark = "购买办公用品" }
            );
        }
      
    }
}
